{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys; sys.path.append('..')\n",
    "from pb_diff_envs.environment.rand_rec_group import RandRectangleGroup \n",
    "import numpy as np\n",
    "\n",
    "env_list_name = 'randSmaze2d-luotest-ipynb-v0'\n",
    "num_groups = 20\n",
    "num_walls = 6\n",
    "maze_size = np.array((5,5))\n",
    "half_extents = np.array((0.5, 0.5))\n",
    "gap_betw_wall = 0.15 # min distance between two walls\n",
    "seed = 27\n",
    "gen_data = True\n",
    "robot_class = None\n",
    "rrg = RandRectangleGroup(env_list_name, num_groups, num_walls, \n",
    "                maze_size, half_extents, gap_betw_wall, seed, gen_data,\n",
    "                robot_class, rand_iter_limit=10000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## get configuration 0\n",
    "center_pos_list = rrg.rec_loc_grp_list[0]\n",
    "hExt_list = rrg.rec_hExt_grp_list[0]\n",
    "## randomly sample an env configuration\n",
    "# center_pos_list, hExt_list = rrg.sample_one_valid_env()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import einops\n",
    "import imageio\n",
    "import matplotlib.pyplot as plt\n",
    "from pb_diff_envs.utils.diffuser_utils import plot2img\n",
    "from importlib import reload;\n",
    "import pb_diff_envs.environment.static.rand_maze2d_renderer as rmr; reload(rmr)\n",
    "from pb_diff_envs.environment.static.rand_maze2d_renderer import RandMaze2DRenderer\n",
    "\n",
    "renderer = RandMaze2DRenderer(fig_dpi=150, num_walls_c=[2, 6])\n",
    "\n",
    "ng =  10\n",
    "# (5, 100, 2)\n",
    "trajs = np.stack([np.linspace(1, 4, 100), np.linspace(2, 3, 100)], axis=1)\n",
    "trajs = [trajs,] * ng\n",
    "\n",
    "ms_list = np.array([maze_size]*ng)\n",
    "hExtgrp_list = np.array([hExt_list]*ng)\n",
    "save_path = None ## or './randmaze2d.png'\n",
    "images = renderer.composite(save_path, trajs, ms_list, rrg.rec_loc_grp_list[:ng], hExtgrp_list)\n",
    "# plt.clf()\n",
    "from utils.maze2d_utils import plt_img, save_img\n",
    "plt_img(images)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "renderer = RandMaze2DRenderer(fig_dpi=100)\n",
    "fig = renderer.plot_maze_bg(ms_list[1], rrg.rec_loc_grp_list[1], hExtgrp_list[1])\n",
    "\n",
    "# fig.savefig( './luotest_bg.pdf', format='pdf', bbox_inches='tight' ) ## save to a pdf\n",
    "img = plot2img(fig)\n",
    "p_len = (40,) * 2\n",
    "img = np.pad(img, ( p_len, p_len, (0,0)), constant_values=255)\n",
    "# imageio.imsave('./luotest_bg.jpg', img[..., :3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "slotformer",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.17"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
